﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MusicOnLine.Models;
using MusicOnLine.Common;
using System.Xml.Linq;
namespace MusicOnLine.Controllers
{
    [Authorize]
    public class PersonalController : Controller
    {
        MusicPlayEntities musicDB = new MusicPlayEntities();
        //
        // GET: /Personal/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Collect()
        {
            return View();
        }

        public ActionResult CollectData(string g,int PageIndex)
        {
            string s = HttpUtility.UrlDecode(g, System.Text.Encoding.GetEncoding("utf-8"));
            string user = HttpContext.User.Identity.Name;
            var model = musicDB.UserAACs.Where(o => o.UserName == user).Join(musicDB.AACInfoes, o => o.AACID, o => o.ID, (m, n) =>
                new { ID = n.ID, Name = n.Name, Artist = n.Artist, Genre = n.Genre, Time = n.Time, PlayedCount = n.PlayedCount, AddDate = m.AddDate, Location = n.Location })
                .Where(o => o.Name.Contains(s)).OrderByDescending(o=>o.AddDate);
            PageList<object> pageMode = new PageList<object>(model, PageIndex, 20);
            return Json(pageMode, JsonRequestBehavior.AllowGet);
        }

        public ActionResult QuickSearch()
        {
            string user = HttpContext.User.Identity.Name;
            var model = musicDB.UserAACs.Where(o => o.UserName == user).Join(musicDB.AACInfoes, o => o.AACID, o => o.ID, (m, n) => n.Name).Take(10).ToList();
            return Json(model,JsonRequestBehavior.AllowGet);
        }

        protected override void Dispose(bool disposing)
        {
            musicDB.Dispose();
            base.Dispose(disposing);
        }

        public ActionResult UploadSingle()
        {

            return View();
        }

        
    }
}
